package com.wuyan.locationdog.ui.device

import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.ext.createEmptyView
import com.arcsoft.commonbase.ext.customShowLong
import com.arcsoft.commonbase.utils.getTestDataList
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.blankj.utilcode.util.ToastUtils
import com.wuyan.locationdog.R
import com.wuyan.locationdog.adapter.VoiceTimeListAdapter
import com.wuyan.locationdog.databinding.VoiceDetailActivityBinding
import com.wuyan.locationdog.viewmodel.MsgViewModel


class VoiceDetailActivity : BaseBindingActivity<VoiceDetailActivityBinding>() {

    private val mViewModel: MsgViewModel by viewModels()

    private val mAdapter by lazy { VoiceTimeListAdapter(R.layout.item_voice_time_line, null) }

    override fun initData() {

        binding.apply {
            setTitleText("听音")


            recyclerView.apply {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                val head = LayoutInflater.from(mActivity).inflate(R.layout.head, recyclerView, false)
                val layoutParams = head.layoutParams
                layoutParams.width = ScreenUtils.getScreenWidth() / 2 - SizeUtils.dp2px(24F)
                head.layoutParams = layoutParams

                mAdapter.addHeaderView(head, 0, LinearLayout.HORIZONTAL)

                val foot = LayoutInflater.from(mActivity).inflate(R.layout.head, recyclerView, false)
                val footlayoutParams = foot.layoutParams
                footlayoutParams.width = ScreenUtils.getScreenWidth() / 2 - SizeUtils.dp2px(24F)
                foot.layoutParams = footlayoutParams
                mAdapter.addFooterView(foot, -1, LinearLayout.HORIZONTAL)

                adapter = mAdapter.apply {
                    setEmptyView(createEmptyView("暂无消息", com.arcsoft.commonbase.R.mipmap.empty_msg))

                    setNewInstance(getTestDataList(55))

//                    mAdapter.addFooterView(HalfWidthView(mActivity))

                    setOnItemClickListener { adapter, view, position ->
                        customShowLong(position.toString())
                    }
                }


                addOnScrollListener(object : OnScrollListener() {
                    var mDx = 0

                    override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                        super.onScrollStateChanged(recyclerView, newState)
                    }

                    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                        super.onScrolled(recyclerView, dx, dy)
                        mDx += dx

                        tvTime.text = (mDx / SizeUtils.dp2px(48F).toFloat()).toString()
                    }
                })
            }

        }


    }


    override fun loadNetData() {
        super.loadNetData()
        val map = HashMap<String, Any>()

    }


    override fun observe() {
        super.observe()

        mViewModel.msgBean.observe(this) {

        }


    }


}